import os
from collections import defaultdict
import click
from loguru import logger


@click.command()
@click.option("--path", help="The path of clip data dir")
def run(path):

    data = defaultdict(lambda: [])
    for filename in os.listdir(path):
        if "txt" in filename:
            continue
        func_type = filename.split("-")[0]
        data[func_type].append(filename)

    for k in data:
        logger.info("{} : {}".format(k, len(data[k])))
        if len(data[k]) > 800:
            reduce = len(data[k]) - 800
            for i in range(reduce):
                os.remove("{}/{}".format(path, data[k][i]))


if __name__ == "__main__":
    run()
